import React, { useEffect, useState } from 'react'
import { Link, useHistory } from 'react-router-dom'
export default function NotFound() {
  const [time, setTime] = useState(5)
  const history = useHistory()
  useEffect(() => {
    let timer = window.setTimeout(() => {
      setTime(time - 1)
    }, 1000)
    if (time === 0) {
      clearTimeout(timer)
      history.push('/home/index')
    }
  }, [time, history])
  return (
    <div>
      <h2>Sorry!,您访问的页面不存在</h2>
      <p>
        {time}秒后返回<Link to="/home/index">主页</Link>
      </p>
    </div>
  )
}
